<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of addNewServer</title>
  <meta name="keywords" content="addNewServer">
  <meta name="description" content="ADDNEWSERVER adds a new DAS service for browsing within the browser">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../index.html">Home</a> &gt;  <a href="index.html">code</a> &gt; addNewServer.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../index.html"><img alt="<" border="0" src="../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for code&nbsp;<img alt=">" border="0" src="../right.png"></a></td></tr></table>-->

<h1>addNewServer
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>ADDNEWSERVER adds a new DAS service for browsing within the browser</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [status] = addNewServer(uri,msgBox) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> ADDNEWSERVER adds a new DAS service for browsing within the browser
 
 ADDNEWSERVER interacts with the DAS Registry and updates a local structure
 that stores all DAS services available for browsing in DASMiner GUI.
 
 SYNTAX: [status] = addNewServer(uri)
          uri - URI identifier of the DAS service, provided by the DAS Registry
          status - 1 (success), 0 (failure).
          
 EXAMPLE:
     create service for Uniprot
     status = addNewServer('DS_409');
     
 See also <a href="populateServerMenu.html" class="code" title="function populateServerMenu(hServerMenu)">POPULATESERVERMENU</a>, <a href="searchRegistry_gui.html" class="code" title="function varargout = searchRegistry_gui(varargin)">SEARCHREGISTRY_GUI</a>

    DASMiner: DAS library and browser for Matlab.
    Diogo Veiga, March 2008.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="checkDASResponse.html" class="code" title="function [isOkay] = checkDASResponse(xmlS,status)">checkDASResponse</a>	CHECKDASRESPONSE used by DASMiner Browser to create a message box about the status of a DAS query</li><li><a href="searchDASRegistry.html" class="code" title="function [xmlStruct, xml,status] = searchDASRegistry(varargin)">searchDASRegistry</a>	SEARCHDASREGISTRY executes the specified query to interact with DAS Registry</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="populateServerMenu.html" class="code" title="function populateServerMenu(hServerMenu)">populateServerMenu</a>	POPULATESERVERMENU reads available DAS services for browsing in DASMiner</li><li><a href="searchRegistry_gui.html" class="code" title="function varargout = searchRegistry_gui(varargin)">searchRegistry_gui</a>	SEARCHREGISTRY_GUI is the GUI for DAS Registry search in Browser</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function [locServ] = add2Servers(locServ, xmlS)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [status] = addNewServer(uri,msgBox)</a>
0002 <span class="comment">% ADDNEWSERVER adds a new DAS service for browsing within the browser</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% ADDNEWSERVER interacts with the DAS Registry and updates a local structure</span>
0005 <span class="comment">% that stores all DAS services available for browsing in DASMiner GUI.</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% SYNTAX: [status] = addNewServer(uri)</span>
0008 <span class="comment">%          uri - URI identifier of the DAS service, provided by the DAS Registry</span>
0009 <span class="comment">%          status - 1 (success), 0 (failure).</span>
0010 <span class="comment">%</span>
0011 <span class="comment">% EXAMPLE:</span>
0012 <span class="comment">%     create service for Uniprot</span>
0013 <span class="comment">%     status = addNewServer('DS_409');</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% See also POPULATESERVERMENU, SEARCHREGISTRY_GUI</span>
0016 <span class="comment">%</span>
0017 <span class="comment">%    DASMiner: DAS library and browser for Matlab.</span>
0018 <span class="comment">%    Diogo Veiga, March 2008.</span>
0019 
0020 
0021 status = 1;
0022 [xmlS, xml,status] = <a href="searchDASRegistry.html" class="code" title="function [xmlStruct, xml,status] = searchDASRegistry(varargin)">searchDASRegistry</a>(<span class="string">'URI'</span>,uri, <span class="string">'timeout'</span>, 5000);
0023 
0024     <span class="keyword">if</span> (~<a href="checkDASResponse.html" class="code" title="function [isOkay] = checkDASResponse(xmlS,status)">checkDASResponse</a>(xmlS,status))
0025         <span class="keyword">return</span>;
0026     <span class="keyword">end</span>
0027 
0028     <span class="keyword">if</span> (isfield(xmlS.SOURCE{1}.VERSION{1},<span class="string">'CAPABILITY'</span>)) <span class="comment">%there should be at least one capability</span>
0029 
0030         <span class="keyword">try</span>
0031             strServer = load(<span class="string">'localServ.mat'</span>, <span class="string">'locServ'</span>);
0032             locServ = strServer.locServ;
0033             
0034             <span class="comment">%check if it is already in</span>
0035             <span class="keyword">for</span> i=1:size(locServ,2)
0036                 <span class="keyword">if</span> (strcmp(locServ(i).uri,uri)) 
0037                     status = 0;
0038                     msgbox(<span class="string">'Selected DAS Service is already available.'</span> ,<span class="string">'DAS Registry Discovery'</span>,<span class="string">'warn'</span>);
0039                     <span class="keyword">return</span>;
0040                 <span class="keyword">end</span>;
0041             <span class="keyword">end</span>
0042             
0043         <span class="keyword">catch</span>
0044             locServ = struct;
0045         <span class="keyword">end</span>
0046         locServ = <a href="#_sub1" class="code" title="subfunction [locServ] = add2Servers(locServ, xmlS)">add2Servers</a>(locServ,xmlS);
0047         save localServ.mat locServ;
0048         <span class="keyword">if</span> (msgBox)
0049             msgbox(<span class="string">'New DAS service was added to the local browser.'</span>,<span class="string">'DAS Registry Discovery'</span>,<span class="string">'warn'</span>);
0050         <span class="keyword">end</span>
0051     <span class="keyword">else</span>
0052         status = 0;
0053         msgbox(<span class="string">'Selected DAS Service has no capabilities described. Service cannot be added.'</span> ,<span class="string">'DAS Registry Discovery'</span>,<span class="string">'warn'</span>);
0054         <span class="keyword">return</span>;
0055     <span class="keyword">end</span>
0056 
0057 <a name="_sub1" href="#_subfunctions" class="code">function [locServ] = add2Servers(locServ, xmlS)</a>
0058 
0059 <span class="keyword">if</span> (isempty(fields(locServ)))
0060     index = 1;
0061 <span class="keyword">else</span>
0062     index = size(locServ,2) + 1;
0063 <span class="keyword">end</span>
0064     
0065 locServ(index).uri = xmlS.SOURCE{1}.ATTRIBUTE.uri;
0066 locServ(index).title = xmlS.SOURCE{1}.ATTRIBUTE.title;
0067 locServ(index).desc = xmlS.SOURCE{1}.ATTRIBUTE.description;
0068 
0069 <span class="comment">%Extracting baseURL and dsn from the query_uri. eg.</span>
0070 <span class="comment">%http://www.ensembl.org/das/Aedes_aegypti.AaegL1.transcript/features</span>
0071 locServ(index).baseUrl = regexp(xmlS.SOURCE{1}.VERSION{1}.CAPABILITY{1}.ATTRIBUTE.query_uri,<span class="string">'[\w\W]*/das/'</span>,<span class="string">'match'</span>);
0072 locServ(index).baseUrl = locServ(index).baseUrl{1};
0073 dsnTokens = regexp(xmlS.SOURCE{1}.VERSION{1}.CAPABILITY{1}.ATTRIBUTE.query_uri,<span class="string">'das/[\w\W]*'</span>,<span class="string">'match'</span>);
0074 <span class="comment">%eg. dsnTokens = 'das/Aedes_aegypti.AaegL1.transcript/features'</span>
0075 tokens = regexp(dsnTokens,<span class="string">'/'</span>,<span class="string">'split'</span>);
0076 locServ(index).dsn = tokens{1}{2};
0077 
0078 
0079 <span class="comment">%Get capability info</span>
0080 <span class="comment">%Get the first capability</span>
0081 tokens = regexp(xmlS.SOURCE{1}.VERSION{1}.CAPABILITY{1}.ATTRIBUTE.type,<span class="string">':'</span>,<span class="string">'split'</span>);
0082 capabilities = tokens{2};
0083 
0084 <span class="keyword">for</span> i=2:size(xmlS.SOURCE{1}.VERSION{1}.CAPABILITY,2)
0085     tokens = regexp(xmlS.SOURCE{1}.VERSION{1}.CAPABILITY{i}.ATTRIBUTE.type,<span class="string">':'</span>,<span class="string">'split'</span>);
0086     capabilities = strcat(capabilities,<span class="string">','</span>,tokens{2});
0087 <span class="keyword">end</span>
0088 
0089 <span class="keyword">if</span> (isempty(regexp(capabilities,<span class="string">','</span>,<span class="string">'split'</span>))) <span class="comment">%1 capability only</span>
0090     locServ(index).capabilities = cellstr(capabilities);
0091 <span class="keyword">else</span>
0092     locServ(index).capabilities = cellstr(regexp(capabilities,<span class="string">','</span>,<span class="string">'split'</span>));
0093 <span class="keyword">end</span>
0094 
0095 <span class="comment">%Get coordinates info</span>
0096 <span class="comment">%Get first coordinate</span>
0097 cs = xmlS.SOURCE{1}.VERSION{1}.COORDINATES{1}.ATTRIBUTE.source;
0098 csURI = xmlS.SOURCE{1}.VERSION{1}.COORDINATES{1}.ATTRIBUTE.uri;
0099 
0100 <span class="keyword">for</span> i=2:size(xmlS.SOURCE{1}.VERSION{1}.COORDINATES,2)
0101    cs = strcat(cs,<span class="string">','</span>,xmlS.SOURCE{1}.VERSION{1}.COORDINATES{i}.ATTRIBUTE.source);
0102    csURI = strcat(csURI,<span class="string">','</span>,xmlS.SOURCE{1}.VERSION{1}.COORDINATES{i}.ATTRIBUTE.uri);
0103 <span class="keyword">end</span>
0104 
0105 <span class="keyword">if</span> (isempty(regexp(cs,<span class="string">','</span>,<span class="string">'split'</span>))) <span class="comment">%1 coordinate only</span>
0106     locServ(index).coordinates = cellstr(cs);
0107     locServ(index).coordinatesURI = cellstr(csURI);
0108 <span class="keyword">else</span>
0109     locServ(index).coordinates = cellstr(regexp(cs,<span class="string">','</span>,<span class="string">'split'</span>));
0110     locServ(index).coordinatesURI = cellstr(regexp(csURI,<span class="string">','</span>,<span class="string">'split'</span>));
0111 <span class="keyword">end</span>
0112 
0113 
0114 
0115 <span class="keyword">if</span> (isfield(xmlS.SOURCE{1}.VERSION{1},<span class="string">'PROP'</span>))
0116 
0117     <span class="keyword">for</span> i=1:size(xmlS.SOURCE{1}.VERSION{1}.PROP,2)
0118         locServ(index).prop(i).name = xmlS.SOURCE{1}.VERSION{1}.PROP{i}.ATTRIBUTE.name;
0119         locServ(index).prop(i).value = xmlS.SOURCE{1}.VERSION{1}.PROP{i}.ATTRIBUTE.value;
0120         locServ(index).prop(i).content = xmlS.SOURCE{1}.VERSION{1}.PROP{i}.CONTENT;
0121     <span class="keyword">end</span>
0122 <span class="keyword">end</span>
0123</pre></div>
<hr><address>Generated on Tue 17-Feb-2009 16:59:45 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>